﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>using System;
using Dapper;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using seejee_Backendium.Core.Interfaces;
using seejee_Backendium.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace seejee_Backendium.Data.Services
{
    public class AccountSetListService : IAccountSetListService
    {
        private readonly string _connectionString;
        private readonly ILogger<AccountSetListService> _logger;
        public AccountSetListService(IConfiguration config, ILogger<AccountSetListService> logger)
        {
            _connectionString = config.GetConnectionString("Default");
            _logger = logger;
        }
        public async Task<IEnumerable<AccountSetList>> GetAllAsync()
        {
            using var connection = new SqlConnection(_connectionString);
            await connection.OpenAsync();

            try
            {
                // 直接查询所有字段（与表结构一致）
                var selectAll = await connection.QueryAsync<AccountSetList>(
                    "SELECT * FROM SEBI_AccountSetList");
                return selectAll;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "获取所有SEBI_AccountSetList记录异常");
            }
            finally
            {
                await connection.CloseAsync();
            }
            return Enumerable.Empty<AccountSetList>(); // 返回空集合而非null，避免控制器空引用
        }
    }
}
